<%@ Page Language="C#" AutoEventWireup="false" MasterPageFile="~/Screens/ScreenMasterPage.master" %>
<asp:Content ContentPlaceHolderID="Head" runat="server">

	<script type="text/javascript">

		window.top.importThemedOshControl(this, "Clock.htc");
		window.top.importThemedOshControl(this, "QuickInfoChannel.htc");
		window.top.importThemedOshControl(this, "QuickInfoVideoFile.htc");
		window.top.importThemedOshControl(this, "QuickInfoProgramPreview.htc");
		window.top.importThemedOshControl(this, "QuickInfoProgram.htc");
		window.top.importThemedOshControl(this, "QuickInfoTimeline.htc");
		window.top.importThemedOshControl(this, "QuickInfoRecording.htc");

		var _isInSeekingMode = false;
		var _programPreviewEnabled = true;
		var _forceNextUIUpdate = false;
		var _timeline = getPlayerTimeline();
		
		function window::onload()
		{
			screen.onCommand.attach(this, onCommand);
			screen.onShow.attach(this, onShow);
			screen.onHide.attach(this, onHide);
			osh.mediaController.onPlayerChange.attach(this, onPlayerChange);
		}
		function window::onunload()
		{
			screen.onCommand.detach(this, onCommand);
			screen.onShow.detach(this, onShow);
			screen.onHide.detach(this, onHide);
			osh.mediaController.onPlayerChange.detach(this, onPlayerChange);
		}

		function getPlayerTimeline()
		{
			var _player = osh.mediaController.getCurrentPlayer();
			return _player ? _player.getTimeline() : null;
		}
		
		function onPlayerChange(sender, e)
		{
			_timeline = (e.newPlayer ? e.newPlayer.getTimeline() : null);
		}

		function onCommand(sender, event)
		{
			var command = event.command.toLowerCase();
			if(command == "playbacknext" || command == "playbackprev" ||
				command == "rewind" || command == "fastforward")
			{
				if(_timeline && _timeline.canSeek())
				{
					_timeline.changeVirtualSeekingSpeed(command == "playbacknext" || command == "fastforward");
					if(isProgramPreviewEnabled())
						preview.prepare();
					screen.stopAutoHideTimer();
				}
				//event.processed = true;
			}
			else if(command == "pause")
			{
				if(_timeline && _timeline.isInSeekingMode())
				{
					_timeline.pauseVirtualSeeking();
				}
				else
					event.processed = false;
			}
			else if(command == "play")
			{
				if(_timeline && _timeline.isInSeekingMode())
				{
					_timeline.stopVirtualSeeking(true);
					screen.restartAutoHideTimer();
				}
				else
					event.processed = false;
			}
			else if(command == "stop")
			{
				if(_timeline && _timeline.isInSeekingMode())
				{
					_timeline.stopVirtualSeeking();
					screen.restartAutoHideTimer();
				}
				event.processed = true; // alway processed to avoid an accidental stop command.
			}
			else if(command == "now")
			{
				program.now();
			}
			else if(command == "description")
			{
				// Turn on/off full program description
				program.fullDescription = !program.fullDescription;
				program.update();
			}
			else if(command == "preview")
			{
				_programPreviewEnabled = !_programPreviewEnabled;
				_forceNextUIUpdate = true;
			}
			else if(command == "prevprogram")
			{
				program.prevProgram();
			}
			else if(command == "nextprogram")
			{
				program.nextProgram();
			}
		}
		
		function onShow(sender, event)
		{
			updateUI();
		}
		
		function onHide(sender, event)
		{
			if(_timeline)
				_timeline.stopVirtualSeeking(false);
		}

		function isProgramPreviewEnabled()
		{
			return _programPreviewEnabled &&
				window.top.Configuration.getCurrent().Osh.Playback.CaptureScreenshots;
		}

		function updateUI(e)
		{
			var timelineSeekingMode = _timeline && _timeline.isInSeekingMode();
			if(_forceNextUIUpdate || _isInSeekingMode != timelineSeekingMode)
			{
				_forceNextUIUpdate = false;
				_isInSeekingMode = timelineSeekingMode;

				if(_isInSeekingMode && isProgramPreviewEnabled())
				{
					preview.disabled = false;
					channel.runtimeStyle.display = "none";
					channel.autoShow = false;
					program.runtimeStyle.display = "none";
					program.autoShow = false;
				}
				else
				{
					preview.disabled = true;
					preview.runtimeStyle.display = "none";
					channel.autoShow = true;
					program.autoShow = true;
					program.update();
				}
			}
			
			if(screen.getVisible())
				osh.refresh();
		}
	</script>

</asp:Content>
<asp:Content ContentPlaceHolderID="Body" runat="server">

	<osh:Clock mode="brief" />

	<div id="InfoBlock">
		<osh:QuickInfoProgramPreview id="preview" />
	
		<osh:QuickInfoVideoFile id="videoFile" mode="brief" />
		
		<osh:QuickInfoChannel id="channel" mode="full" />

		<osh:QuickInfoProgram id="program" />

		<osh:QuickInfoTimeline id="timeline" onchange="updateUI(event)" />
		
		<osh:QuickInfoRecording id="recording" />
	</div>

</asp:Content>
